package com.wgts.wgts.mvp.view.activity.goodsinfo;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.BaseLoadMoreAdapter;
import com.wgts.wgts.netmodle.resp.ProductEvaluateEntity;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class ProductEvaluateAdapter extends BaseLoadMoreAdapter<RecyclerView.ViewHolder> {

    private Context context;

    private List<ProductEvaluateEntity.Evaluate> evaluateEntity;

    private static final  int BODY = 0x0002;

    private static final  int HEAD = 0x0001;

    public ProductEvaluateAdapter(Context context, List<ProductEvaluateEntity.Evaluate> evaluateEntity) {
        super(context);
        this.context = context;
        this.evaluateEntity = evaluateEntity;
    }




    @Override
    public void onBindBodyViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {

        if(viewHolder instanceof ProductEvaluateViewHolder){

            ProductEvaluateEntity.Evaluate evaluate = evaluateEntity.get(i);

            ((ProductEvaluateViewHolder) viewHolder).tvEvaluate.setText(evaluate.evaluateContent);
            MoHuGlide.getInstance().glideImg(context, evaluate.userImage, ((ProductEvaluateViewHolder) viewHolder).circleImageView);
            ((ProductEvaluateViewHolder) viewHolder).customerName.setText(evaluate.userNickname);
            ((ProductEvaluateViewHolder) viewHolder).evaluateTime.setText(evaluate.evaluateTime);
            ((ProductEvaluateViewHolder) viewHolder).tvSpecifications.setText(evaluate.productStandard);
            switch (evaluate.evaluateScore1) {
                case "0":
                    ((ProductEvaluateViewHolder) viewHolder).startOne.setVisibility(View.INVISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).starttwo.setVisibility(View.INVISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startthree.setVisibility(View.INVISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfour.setVisibility(View.INVISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfive.setVisibility(View.INVISIBLE);
                    break;
                case "1":
                    ((ProductEvaluateViewHolder) viewHolder).startOne.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).starttwo.setVisibility(View.INVISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startthree.setVisibility(View.INVISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfour.setVisibility(View.INVISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfive.setVisibility(View.INVISIBLE);
                    break;
                case "2":
                    ((ProductEvaluateViewHolder) viewHolder).startOne.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).starttwo.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startthree.setVisibility(View.INVISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfour.setVisibility(View.INVISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfive.setVisibility(View.INVISIBLE);
                    break;
                case "3":
                    ((ProductEvaluateViewHolder) viewHolder).startOne.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).starttwo.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startthree.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfour.setVisibility(View.INVISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfive.setVisibility(View.INVISIBLE);
                    break;
                case "4":
                    ((ProductEvaluateViewHolder) viewHolder).startOne.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).starttwo.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startthree.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfour.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfive.setVisibility(View.INVISIBLE);
                    break;
                case "5":
                    ((ProductEvaluateViewHolder) viewHolder).startOne.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).starttwo.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startthree.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfour.setVisibility(View.VISIBLE);
                    ((ProductEvaluateViewHolder) viewHolder).startfive.setVisibility(View.VISIBLE);
                    break;
            }
        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateBodyViewHolder(@NonNull ViewGroup viewGroup, int i) {
        if(i == HEAD){
            return new ProductEvaluateHeaderViewHolder(LayoutInflater.from(context).inflate(R.layout.product_evaluate_head, viewGroup, false));
        }
        return new ProductEvaluateViewHolder(LayoutInflater.from(context).inflate(R.layout.evaluate_view_holder, viewGroup, false));
    }


    public class ProductEvaluateViewHolder extends RecyclerView.ViewHolder {

        public CircleImageView circleImageView ;
        public TextView customerName;
        public TextView evaluateTime;
        public ImageView startOne  ;
        public ImageView starttwo  ;
        public ImageView startthree ;
        public ImageView startfour ;
        public ImageView startfive ;
        public TextView tvEvaluate ;
        public TextView tvSpecifications;

        public ProductEvaluateViewHolder(@NonNull View itemView) {
            super(itemView);

             circleImageView = itemView.findViewById(R.id.img_customer_heard);
             customerName = itemView.findViewById(R.id.tv_customer_name);
             evaluateTime = itemView.findViewById(R.id.tv_evaluate_date);
             startOne = itemView.findViewById(R.id.one_start);
             starttwo = itemView.findViewById(R.id.two_start);
             startthree = itemView.findViewById(R.id.thre_start);
             startfour = itemView.findViewById(R.id.four_start);
             startfive = itemView.findViewById(R.id.five_start);
             tvEvaluate = itemView.findViewById(R.id.tv_evaluate);
            tvSpecifications = itemView.findViewById(R.id.tv_specifications);
        }
    }

    public class ProductEvaluateHeaderViewHolder extends RecyclerView.ViewHolder {

        public TextView tvPrice;

        public ProductEvaluateHeaderViewHolder(@NonNull View itemView) {
            super(itemView);
            tvPrice = itemView.findViewById(R.id.tv_praise);
        }
    }


    @Override
    public int getBodyItemCount() {
        return evaluateEntity.size();
    }

    @Override
    public int getBodyItemViewType(int position) {
        return BODY;
    }

}
